package com.zenithmind.version.config.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 版本控制服务安全配置属性 - 遵循开闭原则，支持外部配置
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@Component
@ConfigurationProperties(prefix = "version.security")
public class VersionSecurityProperties {

    /**
     * 认证白名单路径
     */
    private List<String> authWhitelist = List.of(
        "/v3/api-docs/**",
        "/swagger-ui/**",
        "/swagger-ui.html",
        "/doc.html",
        "/webjars/**",
        "/favicon.ico",
        "/knife4j/**",
        "/knife4j-ui/**",
        "/knife4j.html"
    );

    /**
     * 公开端点路径
     */
    private List<String> publicEndpoints = List.of(
        "/api/v1/repositories/public/**",
        "/api/v1/repositories/search",
        "/api/v1/repositories/popular",
        "/api/v1/repositories/latest",
        "/api/v1/repositories/*/preview",
        "/api/v1/commits/public/**",
        "/api/v1/commits/*/preview",
        "/api/v1/file-versions/public/**",
        "/api/v1/file-versions/*/preview",
        "/api/v1/branches/public/**",
        "/api/v1/branches/*/preview",
        "/actuator/**",
        "/health",
        "/info"
    );

    /**
     * 用户角色端点路径
     */
    private List<String> userEndpoints = List.of(
        "/api/v1/repositories/**",
        "/api/v1/commits/**",
        "/api/v1/file-versions/**",
        "/api/v1/branches/**"
    );

    /**
     * 开发者角色端点路径
     */
    private List<String> developerEndpoints = List.of(
        "/api/v1/repositories/create",
        "/api/v1/repositories/*/edit",
        "/api/v1/repositories/*/delete",
        "/api/v1/commits/create",
        "/api/v1/commits/*/revert",
        "/api/v1/branches/create",
        "/api/v1/branches/*/merge",
        "/api/v1/branches/*/delete"
    );

    /**
     * 管理员角色端点路径
     */
    private List<String> adminEndpoints = List.of(
        "/api/v1/repositories/admin/**",
        "/api/v1/commits/admin/**",
        "/api/v1/file-versions/admin/**",
        "/api/v1/branches/admin/**",
        "/api/v1/manage/**"
    );

    /**
     * 是否启用CSRF保护
     */
    private boolean csrfEnabled = false;

    /**
     * 会话创建策略
     */
    private SessionCreationPolicy sessionCreationPolicy = SessionCreationPolicy.STATELESS;

    /**
     * 是否启用OAuth2资源服务器
     */
    private boolean oauth2ResourceServerEnabled = false;

    /**
     * 会话创建策略枚举
     */
    public enum SessionCreationPolicy {
        ALWAYS,
        IF_REQUIRED,
        NEVER,
        STATELESS
    }
}
